package com.zgy.backend.bookstore.service;

import com.zgy.backend.bookstore.mapper.BookMapper;
import com.zgy.backend.bookstore.pojo.Book;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;

/**
 * @Author: renjiaxin
 * @Despcription:
 * @Date: Created in 2020/7/30 0:56
 * @Modified by:
 */
@Service
@Slf4j
public class BookService {
    @Autowired(required = false)
    private BookMapper bookMapper;


    // 获取book
    public Book getBookById(Integer id){
        return bookMapper.selectById(id);
    }


    // 添加book
    public int saveBookEntity(Book book){
        return bookMapper.insert(book);
    }


    // 添加book
    public int saveBookEntity(String name, String author, String publish, Integer pages, Double price){
        Book book = Book.builder().name(name).author(author).publish(publish).pages(pages).price(price).build();
        return bookMapper.insert(book);
    }

    // 更新book
    public int updateBookById(Book book){
        return bookMapper.updateBookById(book);
    }

    // 删除book
    public int deleteBookById(Integer id){
        return bookMapper.deleteById(id);
    }
}
